package com.hhwy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hhwy.controller.utils.Result;
import com.hhwy.domain.PressureCheck;
import com.hhwy.service.IPressureCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pressure/check")
public class PressureCheckController {

    @Autowired
    private IPressureCheckService pressureCheckService;

    @PostMapping
    public Result save(@RequestBody PressureCheck pressureCheck){
        boolean flag = pressureCheckService.save(pressureCheck);
        return new Result(flag?1:0,flag?"添加成功":"添加失败");
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        boolean flag = pressureCheckService.removeById(id);
        return new Result(flag?1:0,flag?"删除成功":"删除失败");
    }

    @PutMapping
    public Result update(@RequestBody PressureCheck pressureCheck){
        boolean flag = pressureCheckService.updateById(pressureCheck);
        return new Result(flag?1:0,flag?"修改成功":"修改失败");
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        PressureCheck pressureCheck = pressureCheckService.getById(id);
        return new Result(1,pressureCheck,"查询成功");
    }

    @GetMapping
    public Result getAll(){
        List<PressureCheck> list = pressureCheckService.list();
        return new Result(1,list,"查询成功");
    }

    @GetMapping("/{currentpage}/{pagesSize}")
    public Result getpage(@PathVariable int currentpage,@PathVariable int pagesSize){
        IPage<PressureCheck> checksIPage = pressureCheckService.getpage(currentpage, pagesSize);
        return new Result(1,checksIPage,"查询成功");
    }




}
